<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="root">

    </div>
</body>
<script src="../react.js"></script>
<script src="../react-dom.js"></script>
<script src="https://cdn.staticfile.org/babel-standalone/6.26.0/babel.min.js"></script>
<script type="text/babel">
    class App extends React.Component{
        render(){
            return(
                <div>
                    {
                        //react 不提倡使用原生js操作DOM如果你非要操作dom,react为我们提供了ref属性来供我们获取dom对象
                    }
                    {
                        // 绑定ref属性 可以通过this.ref.属性名获取dom
                    }
                  <h1 ref="myh1">好好学习天天向上</h1> 
                  <h2 ref="refH2">哈哈哈</h2>
                  <button onClick={()=>{
                    console.log(this)
                    // 获取真实dom对象 this.refs.属性名获取组件实例
                    this.refs.myh1.style.color='red'
                  }}>获取dom对象</button>
                  {
                    // 当ref属性绑定到组件上时 使用this.$refs.属性名获取是组件实例对象
                  }
                  <Child ref='childRef' />   
                  <button onClick={()=>{
                    console.log(this.refs.childRef.state.msg)
                    this.refs.childRef.changeMsg();
                  }}>获取childRef</button>
                </div>
            )
        }
    }
    class Child extends React.Component{
        state={
            msg:"好好学习天天游戏"
        }
        render(){
             return(
                <div>
                    <h3>{this.state.msg}</h3>    
                </div>
             )
        }
        changeMsg(){
            this.setState({
                msg:"学习使我快乐"
            })
        }
    }
    ReactDOM.render(<App/>,document.getElementById("root"))
</script>
</html>